package linwen.wang.controller;

import linwen.wang.commom.ReturnVO;
import linwen.wang.pojo.User;
import linwen.wang.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author zero
 * @DATE 2023/8/2 8:16 AM
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Validated
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping
    public @NotNull ReturnVO fun(@Min(18) int age) {
        log.info("params age=={}",age);
        return null;
    }

    @GetMapping("/fun1")
    public ReturnVO fun1(){
        // 一般来说校验只加在controller上，service不加校验，只做业务逻辑和判空。这里只是我自己实验一下
        // 在@Service上加@Validate也是可以的，能被全局异常校验所处理
        User user = userService.getUser(15);
        return ReturnVO.buildReturnVO(user);
    }
}
